package pages;


import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import com.Users;
import com.google.common.collect.Lists;


public class UserManagmentPage {

	@FindBy (name = "username")
	public WebElement userNameField;
	
	@FindBy (name = "email")
	public WebElement emailField;
	
	@FindBy (id = "password")
	public WebElement passwordField;
	
	@FindBy (id = "password2")
	public WebElement password2Field;
	
	@FindBy (name = "permission")
	public WebElement permissionField;

	@FindBy (name = "submit")
	public WebElement submitButton;

	@FindBy (css = "img[alt=\"Remove\"]	")
	public WebElement removeButton;
	
	@FindBy (css = "div#user-list > table > tbody > tr")
	public List<WebElement> userRows;

	public List<Users> getUsers() {
		List <Users> users = Lists.newArrayList();
		for (WebElement row : userRows) {
			users.add(convertRowToUser(row));
			
		}
		return users;
	}

	public Users convertRowToUser(WebElement row) {
		List<WebElement> cells = row.findElements(By.tagName("td"));
		return new Users().withName(cells.get(1).getText()).withEmail(cells.get(2).getText()).withRole(cells.get(3).getText()); 		
	}
	
	
}
